using System;
using System.Collections.Generic;
using System.IO;
using Windows.ApplicationModel;
using Windows.Storage;

namespace RockHopper.TrainingCalculator.WinRT.Data
{
    public class DataRepository : IDataRepository
    {
        public IEnumerable<string> Get(string name)
        {
            if (DesignMode.DesignModeEnabled) yield return null;

            var uri = new Uri(string.Format("ms-appx:///Assets/{0}.txt", name));
            var file = StorageFile.GetFileFromApplicationUriAsync(uri).AsTask().Result;
            var stream = file.OpenStreamForReadAsync().Result;

            using (var reader = new StreamReader(stream))
            {
                var line = reader.ReadLine();

                while (line != null)
                {
                    yield return line;
                    line = reader.ReadLine();
                }
            }
        }
    }
}